home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 003 / _family / !FamTools / FamGedAwk < prev    next >
Text File  |  1994-06-14  |  3KB  |  135 lines

  1. /* FamGedAwk (for version see "VERS" line below) */
  2.  
  3. BEGIN {
  4.   print "0 HEAD"
  5.   print "1 SOUR Conveted from Acorn Archimedes !Family format"
  6.   print "2 VERS 1.00";                 /* Converter version number */
  7.   print "2 CORP Denis Howe";           /* Author of source software */
  8.   print "3 ADDR <dbh@doc.ic.ac.uk>"
  9.   print "4 CONT 48 Anson Rd., London NW2 3UU, UK"
  10.   print "4 PHON +44 (81) 450 9448"
  11.   print "2 DATA " file
  12.   print "1 DATE " date " " year
  13.   print "1 SUBM @S1@"
  14.   print "1 GEDC"
  15.   print "2 VERS 5.3"
  16.   print "0 @S1@ SUBM"
  17.                                        /* Insert your details here: */
  18.   print "1 NAME Denis Howe"
  19.   print "1 ADDR <dbh@doc.ic.ac.uk>"
  20.   print "2 CONT 48 Anson Rd., London NW2 3UU, UK"
  21.   print "2 PHON +44 (81) 450 9448"  
  22. }
  23. /^$/ { blank = "2 CONT\n"; next }
  24. /^Name:/ {
  25.   Name[++IndiId] = IndiName = value()
  26.   Id[IndiName] = IndiId
  27.   blank = ""
  28.   next
  29. }
  30. /^Sex:/ {
  31.   Sex[IndiId] = IndiSex = $2
  32.   next
  33. }
  34. /^Born:/ {
  35.   Dates[IndiId] = Dates[IndiId] "1 BIRT\n2 DATE " value() "\n"
  36.   next
  37. }
  38. /^Died:/ {
  39.   Dates[IndiId] = Dates[IndiId] "1 DEAT\n2 DATE " value() "\n"
  40.   next
  41. }
  42. /^Mother:/ {
  43.   Mother[IndiId] = value()
  44.   next
  45. }
  46. /^Father:/ {
  47.   Father[IndiId] = value()
  48.   next
  49. }
  50. /^Spouse:/ {
  51.   s = value()
  52.   if (IndiSex == "M")
  53.     f = findfam(IndiName,s,0)
  54.   else
  55.     f = findfam(s,IndiName,0)
  56.   addfam(IndiName,f)
  57.   next
  58. }
  59. /^Child:/ {
  60.   Kid[IndiId,++NKid[IndiId]] = value()
  61.   next
  62. }
  63. /^Person:/ {
  64.   person = value()
  65.   next
  66. }
  67. {
  68.   tag = Notes[IndiId] > "" ? blank "2 CONT" : "1 NOTE"
  69.   blank = ""
  70.   Notes[IndiId] = Notes[IndiId] tag " " $0 "\n"
  71. }
  72. END {
  73.   for (i = 1; i <= IndiId; i++)
  74.     findfam(Father[i],Mother[i],1)
  75.   for (i = 1; i <= IndiId; i++)
  76.   {
  77.     name = Name[i]
  78.     print "0 @I" i "@ INDI"
  79.     print "1 NAME " name
  80.     if (Sex[i] > "") print "1 SEX " Sex[i]
  81.     printf Dates[i]
  82.     for (f = 1; f <= NFams[name]; f++)
  83.       print "1 FAMS @F" Fams[name,f] "@"
  84.     f = findfam(Father[i],Mother[i],0)
  85.     if (f) print "1 FAMC @F" f "@"
  86.     printf Notes[i]
  87.   }
  88.   for (f = 1; f <= NFamily; f++)
  89.   {
  90.     print "0 @F" f "@ FAM"
  91.     if (Husb[f] > "")
  92.     {
  93.       parent = Id[Husb[f]]
  94.       print "1 HUSB @I" parent "@"
  95.     }
  96.     if (Wife[f] > "")
  97.     {
  98.       parent = Id[Wife[f]]
  99.       print "1 WIFE @I" parent "@"
  100.     }
  101.     for (k = 1; k <= NKid[parent]; k++)
  102.     {
  103.       child = Id[Kid[parent,k]]
  104.       if (Mother[child] == Wife[f] && Father[child] == Husb[f])
  105.         print "1 CHIL @I" child "@"
  106.     }
  107.   }
  108.   if (person > "") print "0 @N1@ NOTE Person " person
  109.   print "0 TRLR"
  110. }
  111.  
  112. function value()
  113. {
  114.   $1 = ""
  115.   return substr($0,2)
  116. }
  117.  
  118. function findfam(dad,mum,add,  f)
  119. {
  120.   if (dad == "" && mum == "")
  121.     return 0
  122.   for (f = 1; f <= NFamily; f++)
  123.     if (Husb[f] == dad && Wife[f] == mum)
  124.       return f
  125.   f = ++NFamily;
  126.   Husb[f] = dad; Wife[f] = mum
  127.   if (add) { addfam(dad,f) ; addfam(mum,f) }
  128.   return f
  129. }
  130.  
  131. function addfam(name,fam)
  132. {
  133.   Fams[name,++NFams[name]] = fam
  134. }
  135.